package com.gohome.gohomechat.view.activity;

import android.util.Log;
import android.view.View;
import android.widget.EditText;

import com.gohome.gohomechat.R;
import com.gohome.gohomechat.presenter.RegisterPresenter;
import com.gohome.gohomechat.presenter.presenterlistener.RegisterPresenterInterface;
import com.gohome.gohomechat.ui.viewlistener.RegisterViewInterface;
import com.gohome.gohomechat.utils.ToActivityUtil;
import com.gohome.gohomechat.utils.ToastUtil;

/**
 * Created by dllo on 16/2/29.
 */
public class RegisterActivity extends BaseActivity implements RegisterViewInterface, View.OnClickListener {
    private EditText login_et_account,login_et_password,register_et_againPassword;
    private RegisterPresenterInterface registerPresenterInterface;

    @Override
    protected int getLayout() {
        return R.layout.activity_register;
    }

    @Override
    protected void initPresenter() {
        registerPresenterInterface=new RegisterPresenter(this);
    }

    @Override
    protected void initView() {
        login_et_account=findView(R.id.login_et_account);
        login_et_password=findView(R.id.login_et_password);
        register_et_againPassword=findView(R.id.register_et_againPassword);
        findView(R.id.register_btn_register).setOnClickListener(this);
    }

    @Override
    protected void initData() {
    }

    @Override
    public String userName() {
        return login_et_account.getText().toString().trim();
    }

    @Override
    public String userPsw() {
        return login_et_password.getText().toString().trim();
    }

    @Override
    public String againUserPsw() {
        return register_et_againPassword.getText().toString().trim();
    }

    @Override
    public void showDialog() {
        showProgressDialog();
    }

    @Override
    public void dismissDialog() {
        dismissProgressDialog();
    }

    @Override
    public void toRegisterSuccess() {
        ToastUtil.showToast("注册成功");
        ToActivityUtil.startToActivity(this,MainActivity.class);
        finish();
    }

    @Override
    public void toRegisterFailed_network() {
        ToastUtil.showToast("网络异常，请检查网络！");
    }

    @Override
    public void toRegisterFailed_repeat() {
        ToastUtil.showToast("用户已存在！");
    }

    @Override
    public void toRegisterFailed_withoutPermission() {
        ToastUtil.showToast("注册失败，无权限！");
    }

    @Override
    public void toRegisterFailed_other(String message) {
        ToastUtil.showToast("注册失败:"+message);
        Log.i("ad",message);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.register_btn_register:
                registerPresenterInterface.register();
                break;
        }
    }
}
